//
//  NetworkEngine.m
//  NetworkDemo
//
//  Created by 万孟超 on 2021/9/7.
//

#import "NetworkEngine.h"
#import "NetworkClient.h"

static NSInteger requestIndex = 0;

@interface NetworkEngine()
//绑定的方法
@property (nonatomic, copy) NSString *bindMethod;
//唯一标志索引
@property (nonatomic, assign) NSInteger engineIndex;

@end

@implementation NetworkEngine

/// 初始化方法
/// @param method 绑定的方法名
- (instancetype)initWithRequestMethod:(NSString *)method {
    if (self = [super init]) {
        requestIndex++;
        self.bindMethod = method;
        self.engineIndex = requestIndex;
    }
    return self;
}

/// 取消网络请求
- (void)cancelNetwork {
    [[NetworkClient sharedManager] cancelEngineNetworkTaskWithPoint:self.enginePoint];
}

- (NSString *)enginePoint {
    //索引｜方法名
    return [NSString stringWithFormat:@"%ld|%@",(long)self.engineIndex,self.bindMethod];
}

@end
